{
  LW Filter -- LightWave Image and Pixel Filters

  Image filter plug-ins apply image post processing (filtering) effects to the rendered image.

  Pixel filters apply image processing effects to individual pixels in the rendered image.

  Based on lwfilter.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}

unit LW_Filter;

{$mode objfpc}{$H+}

interface

uses
  LW_Types   ,
  LW_Monitor ,
  LW_Handler ,
  LW_Render  ;

const
  LWIMAGEFILTER_HCLASS   = 'ImageFilterHandler'   ;
  LWIMAGEFILTER_ICLASS   = 'ImageFilterInterface' ;
  LWIMAGEFILTER_GCLASS   = 'ImageFilterGizmo'     ;
  LWIMAGEFILTER_VERSION  = 5 ;

  LWPIXELFILTER_HCLASS   = 'PixelFilterHandler'   ;
  LWPIXELFILTER_ICLASS   = 'PixelFilterInterface' ;
  LWPIXELFILTER_GCLASS   = 'PixelFilterGizmo'     ;
  LWPIXELFILTER_VERSION  = 8 ;

  // Buffer types, used with getLine(), getVal(), setVal()
  LWBUF_SPECIAL                = 0  ;
  LWBUF_LUMINOUS               = 1  ;
  LWBUF_DIFFUSE                = 2  ;
  LWBUF_SPECULAR               = 3  ;
  LWBUF_MIRROR                 = 4  ;
  LWBUF_TRANS                  = 5  ;
  LWBUF_RAW_RED                = 6  ;
  LWBUF_RAW_GREEN              = 7  ;
  LWBUF_RAW_BLUE               = 8  ;
  LWBUF_SHADING                = 9  ;
  LWBUF_SHADOW                 = 10 ;
  LWBUF_GEOMETRY               = 11 ;
  LWBUF_DEPTH                  = 12 ;
  LWBUF_DIFFSHADE              = 13 ;
  LWBUF_SPECSHADE              = 14 ;
  LWBUF_MOTION_X               = 15 ;
  LWBUF_MOTION_Y               = 16 ;
  LWBUF_REFL_RED               = 17 ;
  LWBUF_REFL_GREEN             = 18 ;
  LWBUF_REFL_BLUE              = 19 ;
  LWBUF_DIFF_RED               = 20 ;
  LWBUF_DIFF_GREEN             = 21 ;
  LWBUF_DIFF_BLUE              = 22 ;
  LWBUF_SPEC_RED               = 23 ;
  LWBUF_SPEC_GREEN             = 24 ;
  LWBUF_SPEC_BLUE              = 25 ;
  LWBUF_BACKDROP_RED           = 26 ;
  LWBUF_BACKDROP_GREEN         = 27 ;
  LWBUF_BACKDROP_BLUE          = 28 ;
  LWBUF_PREEFFECT_RED          = 29 ;
  LWBUF_PREEFFECT_GREEN        = 30 ;
  LWBUF_PREEFFECT_BLUE         = 31 ;
  LWBUF_RED                    = 32 ;
  LWBUF_GREEN                  = 33 ;
  LWBUF_BLUE                   = 34 ;
  LWBUF_ALPHA                  = 35 ;
  LWBUF_REFR_RED               = 36 ;
  LWBUF_REFR_GREEN             = 37 ;
  LWBUF_REFR_BLUE              = 38 ;
  LWBUF_REFR_ALPHA             = 39 ;
  LWBUF_NORMAL_X               = 40 ;
  LWBUF_NORMAL_Y               = 41 ;
  LWBUF_NORMAL_Z               = 42 ;
  LWBUF_SURFACEID              = 43 ;
  LWBUF_OBJECTID               = 44 ;
  LWBUF_RADIOSITY_RED          = 45 ;
  LWBUF_RADIOSITY_GREEN        = 46 ;
  LWBUF_RADIOSITY_BLUE         = 47 ;
  LWBUF_AMBIENTOCCLUSION_RED   = 48 ;
  LWBUF_AMBIENTOCCLUSION_GREEN = 49 ;
  LWBUF_AMBIENTOCCLUSION_BLUE  = 50 ;
  LWBUF_UV_TANGENTSPACE_T_X    = 51 ;
  LWBUF_UV_TANGENTSPACE_T_Y    = 52 ;
  LWBUF_UV_TANGENTSPACE_T_Z    = 53 ;
  LWBUF_UV_TANGENTSPACE_B_X    = 54 ;
  LWBUF_UV_TANGENTSPACE_B_Y    = 55 ;
  LWBUF_UV_TANGENTSPACE_B_Z    = 56 ;
  LWBUF_UV_TANGENTSPACE_N_X    = 57 ;
  LWBUF_UV_TANGENTSPACE_N_Y    = 58 ;
  LWBUF_UV_TANGENTSPACE_N_Z    = 59 ;
  LWBUF_CAMERA_TANGENTSPACE_X  = 60 ;
  LWBUF_CAMERA_TANGENTSPACE_Y  = 61 ;
  LWBUF_CAMERA_TANGENTSPACE_Z  = 62 ;
  // for LightWave internal use only
  LWBUF_INTERNAL_1             = 63 ;
  LWBUF_MAX_CHANNELS	       = 64 ;

  { Render flags.}
  LWPFF_MULTITHREADED = 1 shl 0 ;
  LWPFF_EVERYPIXEL    = 1 shl 1 ;
  LWPFF_BEFOREVOLUME  = 1 shl 2 ;
  LWPFF_RAYTRACE      = 1 shl 3 ;

  LWFCF_PREPROCESS    = 1 shl 0 ; // Filter applied in image editor or as pre process

type
  PLWFilterAccess = ^TLWFilterAccess;
  TLWFilterAccess = record
    Width                    ,
    Height        : Integer  ;
    Frame         : TLWFrame ;
    Start                    ,
    End_          : TLWTime  ;
    GetLine       : function
                    (      Type_              ,
                           Y     : Integer    ) : PSingle ;
    SetRGB        : procedure
                    (      X                  ,
                           Y     : Integer    ;
                     const RGB   : TLWFVector ) ;
    SetAlpha      : procedure
                    (      X                  ,
                           Y     : Integer    ;
                           Alpha : Single     ) ;
    Monitor       : PLWMonitor                ;
  end;

  { Note: Flags now returns an arry of index entries.
    The first elements is the number of flags in the array ( count of entries ).
    Followed by array of ( count ) of LWBUF_xxx entries.
    static int flags[] = { 2, LWBUF_SPECIAL, LWBUF_LUMINOUS };  }
  PLWImageFilterHandler = ^TLWImageFilterHandler;
  TLWImageFilterHandler = record
    Inst     : PLWInstanceFuncs;
    Item     : PLWItemFuncs    ;
    Process  : function
               (      Instance    : PLWInstance       ;
                const Access      : PLWFilterAccess   ) : Integer  ;
    Flags    : function
               (      Instance    : PLWInstance       ) : PInteger ;
  end;

  PLWPixelAccess = ^TLWPixelAccess;
  TLWPixelAccess = record
    SX           ,
    SY           : Double ;
    GetVal       : procedure
                   (      Type_                               ,
                          BufLen  : Integer                   ;
                          Buf     : PSingle                   ) ;
    SetRGBA      : procedure
                   ( const RGBA : array {[0..3]} of Single )  ;
    SetVal       : procedure
                   (      Type_                               ,
                          BufLen  : Integer                   ;
                          Buf     : PSingle                   ) ;
    Illuminate               :  TLWIlluminateFunc             ;
    RayTrace                 :  TLWRayTraceFunc               ;
    RayCast                  :  TLWRayCastFunc                ;
    RayShade                 :  TLWRayShadeFunc               ;
    RayTraceMode             :  TLWRayTraceModeFunc           ;
    IlluminateSample         :  TLWIlluminateSampleFunc       ;
    RandomData               :  PRandomFloatData              ;
    RandomFloat              :  TLWRandomFloatFunc            ;
    IlluminateNormal         :  TLWIlluminateNormalFunc       ;
    IlluminateSampleNormal   :  TLWIlluminateSampleNormalFunc ;
    RayTraceData             :  TLWRayTraceDataFunc           ;
    RayTraceShade            :  TLWRayTraceShadeFunc          ;
    Render                   :  PLWRenderData                 ;
    SamplerState             :  PLWSamplerState               ;
    GetSamplerRange          :  TLWGetSamplerRangeFunc        ;
    GetSample2D              :  TLWGetSample2DFunc            ;
    GetSample1D              :  TLWGetSample1DFunc            ;
  end;

  PLWPixelFilterHandler = ^TLWPixelFilterHandler;
  LWPixelFilterHandler  = record
    Inst        : PLWInstanceFuncs;
    Item        : PLWItemFuncs    ;
    Rend        : PLWRenderFuncs  ;

    Evaluate    : procedure
                  (      Instance : PLWInstance       ;
                   const Access   : PLWPixelAccess) ;
    Flags       : function
                  (      Instance : PLWInstance       ) : PInteger;
    RenderFlags : function
                  (      Instance : PLWInstance       ) : UInt32;
  end;

  TLWFilterContext = Uint32;

implementation

end.

